<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <title>Document</title>
 <style type="text/css">
 *{padding: 0;margin: 0;}
 .container{
  width: 273px;height: 163px;overflow: hidden;
  position: relative;margin: 0 auto;
 }
 .list{
  position: absolute;width: 1638px;top: 0;left: 0px;
 }
 .list li{
  float: left;list-style: none;
 }
 .btn{
  position: absolute;display: block;width: 40px;height: 50px;font-size: 40px;
  text-align: center;font-weight: bold;top: 50%;margin-top: -25px;background-color: rgba(255,255,255,0.5);cursor:pointer;
 }
 .btn:hover{
  background-color: rgba(0,0,0,0.3);color: #fff;
 }
 .pre{
  left: 0;
 }
 .next{
  right: 0;
 }
 .nav{
  position: absolute;bottom: 5px;display: flex;justify-content: center;width: 100%;
 }
 .nav span{
  width: 10px;height: 10px;border-radius: 10px;background-color: #fff;z-index: 2;display: inline-block;margin-right: 10px;cursor: pointer;
 }
 span.on{
  background-color: orange;
 }
 img{
 width:273px;
height:163px;
 }
 </style>
</head>
<body>
 <div class="container">
 <ul class="list" style="left: 0px">
  <li><img src="images/1.jpg" alt=""></li>
  <li><img src="images/2.jpg" alt=""></li>
  <li><img src="images/3.jpg" alt=""></li>
 </ul>
 <div class="nav">
  <span class="on"></span>
  <span></span>
  <span></span>
  <span></span>
  <span></span>
 </div>
 <em class="next btn">></em>
 <em class="pre btn"><</em>
 </div>
 <script type="text/javascript" src="js/jquery-1.8.3.min.js"></script>
 <script type="text/javascript">
 $(function(){
  var i=0;
  $('.next').click(function(){
  i++;
  console.log(i);
  
  moveImg(i);
    
  });
  $('.pre').click(function(){
  i--;
  moveImg(i);
    
  });
  $('.nav span').click(function(){
  var _index=$(this).index();
  i=_index;
  moveImg(i);
  
    
  });
  // i的作用：决定下一张图片是谁————也就是说ul的left是多少。
  // $('.list').css({left)的值是从图a过度是此时的ul的left。
  function moveImg(){
  if (i==6) {
   i=1;
   $('.list').css({'left':'0'});
  }
   // 是第一张
  if(i==-1){
   i=4;
   $('ul').css({left:(5*-273)});
  }
  $('.list').stop().animate({'left':-273*i+'px'},1000);
  if (i==5) {
  $('.nav span').eq(0).addClass('on').siblings().removeClass('on');
  
  }
  $('.nav span').eq(i).addClass('on').siblings().removeClass('on');
  
  }
 })
 </script>
</body>
</html>